#!/usr/bin/env python
from onsocial.lib.base import wsgify, render, webenv
from formencode import htmlfill

from paste.deploy import CONFIG
import webob
import simplejson

from onsocial import model

@wsgify()
def index():
    users = model.User.query.all()
    return render('people/index.html', users=users)

@wsgify()
def show(nickname):
    user = model.User.query.filter_by(nickname=nickname).one()
    return render('people/show.html', user=user)

@wsgify()
def update(nickname):
    user = model.User.query.filter_by(nickname=nickname).one()
    input = simplejson.load(webenv.request.environ['wsgi.input'])
    user.profile = input['profile']
    model.Session.commit()
    return user.profile

def routing(app):
    app.add('/people', GET=index)
    app.add('/people/{nickname}', GET=show, PUT=update)
    
    